package com.ruoyi.wapp.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.system.domain.SysDictData;
import com.ruoyi.system.domain.WdyNotice;
import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.system.service.IWdyNoticeService;
import com.ruoyi.wapp.controller.base.BaseController;
import com.ruoyi.wapp.controller.base.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class WdyNoticeController extends BaseController {

    @Autowired
    private IWdyNoticeService wdyNoticeService;
    @Autowired
    private ISysDictDataService dictDataService;
    /**
     * 查询新闻公告列表
     */
    @PostMapping("wdyNotice/list")
    @ResponseBody
    public Result list(Integer pageNum, Integer pageSize, WdyNotice wdyNotice)
    {
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<WdyNotice> list = wdyNoticeService.getWdyNoticeList(wdyNotice);
            List<SysDictData> sysDictData=   dictDataService.selectDictDataByType("wdy_notice_type");
            PageInfo page = new PageInfo(list);
            page.setList(null);
            return Result.ok().put("page", page).put("list", list).put("sysDictData",sysDictData);
        }catch (Exception e){
            return Result.error("9999", MessageUtils.message("msg.transfer.error"));
        }
    }


    /**
     * 修改新闻公告
     */
    @PostMapping("wdyNotice/edit")
    public Result edit( Long id )
    {
        try {
            WdyNotice wdyNotice = wdyNoticeService.selectWdyNoticeById(id);
            return Result.ok().put("wdyNotice", wdyNotice);
        }catch (Exception e){
            return Result.error("9999", MessageUtils.message("msg.transfer.error"));
        }
    }
    @PostMapping("wdyNotice/dictType")
    public Result sysDictData(String dictType ){
        try {
            List<SysDictData> sysDictData=   dictDataService.selectDictDataByType(dictType);
            return Result.ok().put("sysDictData", sysDictData);
        }catch (Exception e){
            return Result.error("9999", MessageUtils.message("msg.transfer.error"));
        }

    }



}
